<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <style>
      .wrap {
        width: 300px;
        height: 400px;
        border: 1px solid #000;
        overflow: auto;
        margin-right: 100px;
      }
      li {
        border: 1px solid #000;
        width: 230px;
        list-style: none;
      }
      .list-enter-active,
      .list-leave-active {
        transition: all 0.5s ease;
      }
      .list-enter-from,
      .list-leave-to {
        opacity: 0;
        transform: translateX(100%);
      }
    </style>
  </head>
  <body>
    <div id="app" style="display: flex">
      <!-- <pass :list="passList" title="及格的"></pass>
      <pass :list="nopassList" title="不及格的"></pass> -->
      <pass :list="passList">及格的</pass>
      <pass :list="nopassList">不及格的</pass>
    </div>

    <script src="./lib/vue3.js"></script>
    <script>
      const { createApp } = Vue;

      const Pass = {
        props: ["list", "title"],
        template: `
          <div>
            <h3><slot></slot></h3>
            <transition-group name="list" tag="ul" class="wrap">
              <li v-for="item in list" :key="item.id">
                <p>姓名:{{ item.name }}</p>
                <p>生日:{{ format(item.birthday) }}</p>
                <p>分数:{{ item.score }} - <input type="number" v-model="item.score" /></p>
              </li>
            </transition-group>
          </div>
        `,
        methods: {
          format(val) {
            let time = new Date(val);
            let year = time.getFullYear();
            let month = time.getMonth() + 1;
            let date = time.getDate();
            let hours = time.getHours();
            let minute = time.getMinutes();
            let second = time.getSeconds();

            if (month < 10) {
              month = "0" + month;
            }
            if (date < 10) {
              date = "0" + date;
            }
            if (hours < 10) {
              hours = "0" + hours;
            }
            if (minute < 10) {
              minute = "0" + minute;
            }
            if (second < 10) {
              second = "0" + second;
            }
            return (
              year +
              "-" +
              month +
              "-" +
              date +
              " " +
              hours +
              ":" +
              minute +
              ":" +
              second
            );
          },
        },
      };

      createApp({
        data() {
          return {
            list: [],
            // passList: [],
          };
        },
        mounted() {
          fetch("http://10.31.167.14:3000/")
            .then((response) => response.json())
            .then((res) => {
              // console.log(res.list);
              this.list = res.list;
              console.log(this.list);
              // this.passList = this.list.filter((item) => item.score >= 60);
              // this.nopassList = this.list.filter((item) => item.score < 60);
            });
        },
        computed: {
          passList() {
            return this.list.filter((item) => item.score >= 60);
          },
          nopassList() {
            return this.list.filter((item) => item.score < 60);
          },
        },
        components: {
          Pass,
        },
      }).mount("#app");
    </script>
  </body>
</html>
